#include "Scanner.h"

typedef LALG::Parser::token token;

namespace LALG
{

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Scanner
 *      Method:  Scanner
 * Description:  Contrói um analisador léxico passando o stream de entrada e a
 *               tabela de palavras reservadas
 *--------------------------------------------------------------------------------------
 */
Scanner::Scanner(Driver &cDriver) :
        yyFlexLexer(&(cDriver.istream)), driver(cDriver)
{
}

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Scanner
 *      Method:  yylex
 * Description:  Função de scaneamento com valor semântico
 *--------------------------------------------------------------------------------------
 */
int Scanner::yylex(Parser::semantic_type* lval)
{
    yylval = lval;
    return yylex();
}

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Scanner
 *      Method:  checkID
 * Description:  Verifica o tipo do identificador reconhecido
 *--------------------------------------------------------------------------------------
 */
int Scanner::checkID()
{
    return driver.reserved[yytext];
}

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Scanner
 *      Method:  printError
 * Description:  Imprime um erro
 *--------------------------------------------------------------------------------------
 */
void Scanner::printError(ErrorWhat what)
{
    driver.lexError(what, yytext);
}

}
